fix(redirect): suppress stderr from builtins with 2>/dev/null#1138
Merged
fix(redirect): suppress stderr from builtins with 2>/dev/null#1138
Conversation
Two bugs fixed:
1. Compound commands with output redirects (e.g. `{ cmd; } 2>/dev/null`)
leaked stderr via output_callback before apply_redirections ran.
Fix: suspend output_callback during compound body execution when
output redirects are present.
2. Glob error sentinel path in execute_simple_command returned early
without calling apply_redirections, so `shopt -s failglob; cmd *.x
2>/dev/null` still showed the error.
Fix: route the sentinel error through apply_redirections.
Closes #1116
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{ cmd; } 2>/dev/null) leaking stderr via output_callback beforeapply_redirectionsranexecute_simple_commandreturning early without callingapply_redirectionsWhat
Two bugs caused
2>/dev/nullto not suppress stderr from builtins:Streaming callback leak: When
output_callbackis set (streaming mode), compound commands like{ ls /nonexistent; } 2>/dev/nullemitted stderr via the callback during body execution, before the outer redirect could suppress it. Fix: suspendoutput_callbackduring compound body execution when output redirects are present.Glob sentinel bypass: When
shopt -s failglobis enabled and a glob has no matches, the error sentinel path returnedExecResult::err()directly without routing throughapply_redirections. Fix: pass the error result throughapply_redirections.Tests
test_stderr_redirect_devnull_simple_and_compound(simple, compound, &>, failglob)test_stderr_redirect_devnull_streaming(compound + callback)redirect_stderr_suppress_ls,redirect_stderr_suppress_compound,redirect_combined_suppress_lsCloses #1116